<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
	include("access/opendb.php");
	include('user_type/system.php');
	include('access/login_functions.php');
	include('process/processSearch.php');		
	
	$_SESSION['restricted'] = false;	

	$results = Search();
?>

<head>	
	<link rel="stylesheet" type="text/css" href="style_1.css">
	<title>Page Results</title>
	<script type="text/javascript" src="js/tools.js"></script>
</head>
<body onload="set_to_search_bar();">
<div class="above_body"> <!-- closing tag is in template navbar -->
	<div id="header" class="floatcontainer doc_header">
		<div><a name="top" href="home.php" class="logo-image"><img src="images\QUESTwtrl2.png"  title=""></a></div>
			<div id="toplinks" class="toplinks">
			
				<ul class="nouser">
				
					<?php if (!isset($_SESSION['user'])) echo "<li><a href=\"register.php\" rel=\"nofollow\">Register</a></li>"; ?>
				
					<li>
					
					<form id="navbar_loginform" action="access/login.php" method="post" >
					<input type="hidden" name="currentPage" value="<?php echo System::curPageName(); ?>" />
						<fieldset id="logindetails" class="logindetails">
							<div>
								<div>
							
							<?php // check if user is logged in
							if(isset($_SESSION['user']))
							{	$user = $_SESSION['user'];
								$_SESSION['curPage'] = System::curPageName(); 
								// if so, display username with tools
								echo "<div style=\"font-size: 16px; font-weight: bold;\">";
								echo "Welcome, $user <br />";
								echo "<a href=\"access/logout.php\">Log Out</a>";
								echo "<a href=\"userTools.php\">myTools</a>";
								echo "<a href=\"userInfo.php\">myProfile</a>";
								
								echo "</div>";
							}
							else
							{	// otherwise, display login form
								echo "<input type=\"text\" class=\"textbox default-value\" name=\"user\" id=\"navbar_username\" size=\"10\" tabindex=\"101\" value=\"Username\"> ";
								echo "<input type=\"password\" class=\"textbox default-value\" tabindex=\"102\" name=\"pass\" id=\"navbar_password_hint\" size=\"10\" value=\"Password\" style=\"display: inline; \"> ";
								echo "<input type=\"submit\" class=\"loginbutton\" tabindex=\"104\" value=\"Log in\" title=\"Enter your username and password in the boxes provided to login.\" accesskey=\"s\">";
							}
						?>
					</form>
					</li>
				</ul>
			</div>
	</div> 
	<div id="navbar" class="navbar">

		<ul id="navtabs" class="navtabs floatcontainer">					
		</ul>
	</div>
</div><!-- closing div for above_body -->
 
	


<form action="Captcha.php" id="mainsearch" method="post" class="vbform block">
	<div style="padding:5px">
		<center>
			<input type="text" style="font-size: 13pt; float: left;" name="search" id="search" value="<?php echo $_SESSION['search']; ?>" size="65">
			<input type="submit"  style="font-size: 11pt; text-align:center; height: 27px; width: 180px; float: left;" class="button" value="Search" size="20">
			<input type="hidden" name="searchType" value="<?php echo $_SESSION['searchType']; ?>" />
		</center>
	</div>
	
	<br /><br />

	
	<?php
		if (trim($_SESSION['searchType']) == "Search Images")
		{
			echo "<div class=\"article_block\">";
			echo "<h2 class=\"blockhead\">Search Results</h2>";
			echo "<div class=\"album\">";
		}
		else
		{
			echo "<div class=\"section\">";
			echo "<h2 class=\"blockhead\">Search Results</h2>";
			echo "<div class=\"blockbody formcontrols\">";
		}
		
		// filename, username, UID, CID
		// produce search results
		
		$c = count($results);
		if ($c == 0)
		{
			echo "<div class=\"blockrow\">";
			echo "No results found.";
			echo "</div>";
		}
		
		for ($i = 0; $i < $c; $i++)
		{	
			$fileSource = $results[$i][0];
			$filesize = round(filesize($results[$i][0]) / 1024);
			
			$views = $results[$i][5];
			list($width,$height) = getimagesize($fileSource);
			$username = $results[$i][1];
			$UID = $results[$i][2];
			$CID = $results[$i][3];
					
			if (trim($_SESSION['searchType']) == "Search Images")	// perform image search
			{	$imgtitle = System::get_image_title($fileSource);
				echo "<div class=\"imageSingle\">";
				echo "<div class=\"image\"><a href=\"image_Page.php?CID=$CID\"><img src=\"$fileSource\" alt=\"$imgtitle\" width=\"150\" height=\"150\" ></a></div>";
				echo "<div class=\"footer\">";
				echo "<ul>";
				echo "<li><u><a href=\"image_Page.php?CID=$CID\">$imgtitle</u></a></li>";
				echo "<li style=\"color:#00FFFF\">$filesize KB - [$width x $height]</li>";
				echo "</ul>";
				echo "</div>";
				echo "</div>";
			}
			else 	// perform article search
			{	$lastMod = $results[$i][4];
				$body = System::get_body($fileSource);
				$body = substr($body,0,106);
				$arttitle = System::get_title($fileSource);				
				echo "<div class=\"blockrow\">";
				echo "<li><b><a href=\"article_Page.php?CID=$CID\">$arttitle</a></b></li>";
				echo "<li>$body ....</li>";
				echo "<li style=\"color:#0000CC\">Written By: $username";
				echo " - $filesize KB - Last Modified: $lastMod - Views: $views </li>";
				echo "</div>";
			}
		}
		
		if (!isset($_SESSION['user']))
			if ($_SESSION['lastListingID'] > -1)	// that means there are more search listings
				echo "<input type=\"submit\" class=\"button\" value=\"More search listings . . .\" />";
	?>
		</div>
	</div>
</form>
<div id="footer" class="floatcontainer footer">

		<center><a href="">Contact WebMaster</a></center>
 

</div>
 </body></html>